/**
 * 
 */

package com.chengyu.eyc.listener;

import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * @author kevin
 *
 */
@Slf4j
@Component
public class SimpleMessageListener {

    @Bean("simpleMessageQueue")
    public Queue createQueue() {
        return new Queue("test", false);
    }
    
    @Bean("messageListenerContainer")
    public SimpleMessageListenerContainer messageListenerContainer(ConnectionFactory connectionFactory,@Qualifier("simpleMessageQueue") Queue queue) {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.setQueues(queue);
//        container.setQueueNames();
        container.setMessageListener((MessageListener)message -> {
            log.info("====接收到" + message.getMessageProperties().getConsumerQueue() + "队列的消息=====");
            log.info(message.getMessageProperties()+"");
            log.info(new String(message.getBody()));
        });
        return container;
    }

}
